package com.zengqingfa.examples.mybatisplus.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.zengqingfa.examples.mybatisplus.context.UserInfoContext;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

/**
 * @fileName: MyMetaObjectHandler
 * @author: zengqf3
 * @date: 2020-8-2 15:54
 * @description:
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    /**
     * 插入值
     *
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createUserCode", UserInfoContext.getUser(), metaObject);
        this.setFieldValByName("updateUserCode",  UserInfoContext.getUser(), metaObject);
    }

    /**
     * 插入和更新时插入值
     *
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateUserCode", UserInfoContext.getUser(), metaObject);
    }
}
